home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / g__~1 / gpinc20.zoo / streambu.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-13  |  18.9 KB  |  585 lines

  1. //    This is part of the iostream library, providing -*- C++ -*- input/output.
  2. //    Copyright (C) 1991 Per Bothner.
  3. //
  4. //    This library is free software; you can redistribute it and/or
  5. //    modify it under the terms of the GNU Library General Public
  6. //    License as published by the Free Software Foundation; either
  7. //    version 2 of the License, or (at your option) any later version.
  8. //
  9. //    This library is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12. //    Library General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU Library General Public
  15.  
  16.  
  17. #ifndef _STREAMBUF_H
  18. #define _STREAMBUF_H
  19. #ifdef __GNUG__
  20. #pragma interface
  21. #endif
  22.  
  23. /* #define _G_IO_THROW */ /* Not implemented:  ios::failure */
  24.  
  25. #include <g_config.h>
  26. #ifdef _G_NEED_STDARG_H
  27. #include <stdarg.h>
  28. #endif
  29.  
  30. #ifndef atarist
  31. #ifndef EOF
  32. #define EOF (-1)
  33. #endif
  34. #ifndef NULL
  35. #ifdef __GNUC__
  36. #define NULL ((void*)0)
  37. #else
  38. #define NULL (0)
  39. #endif
  40. #endif
  41. #else
  42. #include <stddef.h>
  43. #include <stdio.h>
  44. extern "C" unsigned long __DEFAULT_BUFSIZ__;
  45. #endif
  46.  
  47. class ostream; class streambuf; class backupbuf;
  48.  
  49. // In case some header files defines these as macros.
  50. #undef open
  51. #undef close
  52.  
  53. #ifdef _G_FRIEND_BUG
  54. extern int __UNDERFLOW(streambuf*);
  55. extern int __OVERFLOW(streambuf*, int);
  56. #endif
  57. extern "C" int __underflow(streambuf*);
  58. extern "C" int __overflow(streambuf*, int);
  59.  
  60. typedef _G_off_t streamoff;
  61. typedef _G_off_t streampos; // Should perhaps be _G_fpos_t ?
  62.  
  63. typedef unsigned long __fmtflags;
  64. typedef unsigned char __iostate;
  65.  
  66. struct _ios_fields { // The data members of an ios.
  67.     streambuf *_strbuf;
  68.     ostream* _tie;
  69.     int _width;
  70.     __fmtflags _flags;
  71.     _G_wchar_t _fill;
  72.     __iostate _state;
  73.     __iostate _exceptions;
  74.     int _precision;
  75. };
  76.  
  77. #define _IOS_GOOD    0
  78. #define _IOS_EOF    1
  79. #define _IOS_FAIL    2
  80. #define _IOS_BAD    4
  81.  
  82. #define _IOS_INPUT    1
  83. #define _IOS_OUTPUT    2
  84. #define _IOS_ATEND    4
  85. #define _IOS_APPEND    8
  86. #define _IOS_TRUNC    16
  87. #define _IOS_NOCREATE    32
  88. #define _IOS_NOREPLACE    64
  89. #define _IOS_BIN    128
  90. #ifdef atarist
  91.   /* force text mode */
  92. #define _IOS_TEXT    256
  93. #endif
  94.  
  95. #ifdef _STREAM_COMPAT
  96. enum state_value {
  97.     _good = _IOS_GOOD,
  98.     _eof = _IOS_EOF,
  99.     _fail = _IOS_FAIL,
  100.     _bad = _IOS_BAD };
  101. enum open_mode {
  102.     input = _IOS_INPUT,
  103.     output = _IOS_OUTPUT,
  104.     atend = _IOS_ATEND,
  105.     append = _IOS_APPEND
  106. #ifdef atarist
  107.     ,
  108.     in_bin =_IOS_INPUT|_IOS_BIN,  // force bin mode regardless of default mode
  109.     out_bin=_IOS_OUTPUT|_IOS_BIN,
  110.     app_bin=_IOS_APPEND|_IOS_BIN,
  111.     binary = _IOS_BIN,              // flag that may be or'ed in
  112.  
  113.     in_text=_IOS_INPUT|_IOS_TEXT,    // force text mode
  114.     out_text=_IOS_OUTPUT|_IOS_TEXT,
  115.     app_text=_IOS_APPEND|_IOS_TEXT,
  116.     text=_IOS_TEXT                // flag that may be or'ed in
  117. #endif
  118.  };
  119. #endif
  120.  
  121. class ios : public _ios_fields {
  122.   public:
  123.     typedef __fmtflags fmtflags;
  124.     typedef int iostate;
  125.     typedef int openmode;
  126.     typedef int streamsize;
  127.     enum io_state {
  128.     goodbit = _IOS_GOOD,
  129.     eofbit = _IOS_EOF,
  130.     failbit = _IOS_FAIL,
  131.     badbit = _IOS_BAD };
  132.     enum open_mode {
  133.     in = _IOS_INPUT,
  134.     out = _IOS_OUTPUT,
  135.     ate = _IOS_ATEND,
  136.     app = _IOS_APPEND,
  137.     trunc = _IOS_TRUNC,
  138.     nocreate = _IOS_NOCREATE,
  139.     noreplace = _IOS_NOREPLACE,
  140.     bin = _IOS_BIN
  141. #ifdef atarist
  142.     ,
  143.     in_bin = _IOS_INPUT|_IOS_BIN,
  144.     out_bin = _IOS_OUTPUT|_IOS_BIN,
  145.         ate_bin = _IOS_ATEND|_IOS_BIN,
  146.     app_bin = _IOS_APPEND|_IOS_BIN,
  147.         binary = _IOS_BIN,
  148.  
  149.     in_text = _IOS_INPUT|_IOS_TEXT,
  150.     out_text = _IOS_OUTPUT|_IOS_TEXT,
  151.         ate_text = _IOS_ATEND |_IOS_TEXT,
  152.     app_text = _IOS_APPEND|_IOS_TEXT,
  153.         text = _IOS_TEXT
  154. #endif
  155.  };
  156.     enum seek_dir { beg, cur, end};
  157.     // ANSI: typedef enum seek_dir seekdir; etc
  158.     enum { skipws=01, left=02, right=04, internal=010,
  159.        dec=020, oct=040, hex=0100,
  160.        showbase=0200, showpoint=0400, uppercase=01000, showpos=02000,
  161.        scientific=04000, fixed=010000, unitbuf=020000, stdio=040000,
  162.        dont_close=0100000 //Don't delete streambuf on stream destruction
  163.        };
  164.     enum { // Masks.
  165.     basefield=dec+oct+hex,
  166.     floatfield = scientific+fixed,
  167.     adjustfield = left+right+internal
  168.     };
  169.  
  170. #ifdef _G_IO_THROW
  171.     class failure : public xmsg {
  172.     ios* _stream;
  173.       public:
  174.     failure(ios* stream) { _stream = stream; }
  175.     failure(string cause, ios* stream) { _stream = stream; }
  176.     ios* rdios() const { return _stream; }
  177.     };
  178. #endif
  179.  
  180.     ostream* tie() const { return _tie; }
  181.     ostream* tie(ostream* val) { ostream* save=_tie; _tie=val; return save; }
  182.  
  183.     // Methods to change the format state.
  184.     _G_wchar_t fill() const { return (_G_wchar_t)_fill; }
  185.     _G_wchar_t fill(_G_wchar_t newf)
  186.     {_G_wchar_t oldf = (_G_wchar_t)_fill; _fill = (char)newf; return oldf;}
  187.     fmtflags flags() const { return _flags; }
  188.     fmtflags flags(fmtflags new_val) {
  189.     fmtflags old_val = _flags; _flags = new_val; return old_val; }
  190.     int precision() const { return _precision; }
  191.     int precision(int newp) {
  192.     unsigned short oldp = _precision; _precision = (unsigned short)newp;
  193.     return oldp; }
  194.     fmtflags setf(fmtflags val) {
  195.     fmtflags oldbits = _flags;
  196.     _flags |= val; return oldbits; }
  197.     fmtflags setf(fmtflags val, fmtflags mask) {
  198.     fmtflags oldbits = _flags;
  199.     _flags = (_flags & ~mask) | (val & mask); return oldbits; }
  200.     fmtflags unsetf(fmtflags mask) {
  201.     fmtflags oldbits = _flags & mask;
  202.     _flags &= ~mask; return oldbits; }
  203.     int width() const { return _width; }
  204.     int width(int val) { int save = _width; _width = val; return save; }
  205.  
  206. #ifdef _G_IO_THROW
  207.     void _throw_failure() { throw new ios::failure(this); }
  208. #else
  209.     void _throw_failure() { }
  210. #endif
  211.  
  212.     streambuf* rdbuf() const { return _strbuf; }
  213.     void clear(iostate state = 0) {
  214.     _state = _strbuf ? state : state|badbit;
  215.     if (_state & _exceptions) _throw_failure(); }
  216.     void set(iostate flag) { _state |= flag;
  217.     if (_state & _exceptions) _throw_failure(); }
  218.     void setstate(iostate flag) { _state |= flag; // ANSI
  219.     if (_state & _exceptions) _throw_failure(); }
  220.     int good() const { return _state == 0; }
  221.     int eof() const { return _state & ios::eofbit; }
  222.     int fail() const { return _state & (ios::badbit|ios::failbit); }
  223.     int bad() const { return _state & ios::badbit; }
  224.     iostate rdstate() const { return _state; }
  225.     operator void*() const { return fail() ? (void*)0 : (void*)(-1); }
  226.     int operator!() const { return fail(); }
  227.     iostate exceptions() const { return _exceptions; }
  228.     void exceptions(iostate enable) {
  229.     _exceptions = enable;
  230.     if (_state & _exceptions) _throw_failure(); }
  231.  
  232.     static int sync_with_stdio(int on);
  233.     static void sync_with_stdio() { sync_with_stdio(1); }
  234.  
  235. #ifdef _STREAM_COMPAT
  236.     void unset(state_value flag) { _state &= ~flag; }
  237.     void close();
  238.     int is_open();
  239.     int readable();
  240.     int writable();
  241. #endif
  242.  
  243.     // Used to initialize standard streams. Not needed in this implementation.
  244.     class Init {
  245.     public:
  246.       Init () { }
  247.     };
  248.  
  249.   protected:
  250.     ios(streambuf* sb = 0, ostream* tie = 0);
  251.     virtual ~ios();
  252.     void init(streambuf* sb) { _state=0; _strbuf=sb; }
  253. };
  254.  
  255. #if __GNUG__==1
  256. typedef int _seek_dir;
  257. #else
  258. typedef ios::seek_dir _seek_dir;
  259. #endif
  260.  
  261. // Magic numbers and bits for the _flags field.
  262. // The magic numbers use the high-order bits of _flags;
  263. // the remaining bits are abailable for variable flags.
  264. // Note: The magic numbers must all be negative if stdio
  265. // emulation is desired.
  266.  
  267. #define _IO_MAGIC 0xFBAD0000 /* Magic number */
  268. #define _OLD_STDIO_MAGIC 0xFABC0000 /* Emulate old stdio. */
  269. #define _IO_MAGIC_MASK 0xFFFF0000
  270. #define _S_USER_BUF 1 /* User owns buffer; don't delete it on close. */
  271. #define _S_UNBUFFERED 2
  272. #define _S_NO_READS 4 /* Reading not allowed */
  273. #define _S_NO_WRITES 8 /* Writing not allowd */
  274. #define _S_EOF_SEEN 0x10
  275. #define _S_ERR_SEEN 0x20
  276. #define _S_DELETE_DONT_CLOSE 0x40
  277. #define _S_LINKED 0x80 // Set if linked (using _chain) to streambuf::_list_all.
  278. #define _S_IN_BACKUP 0x100
  279. #define _S_LINE_BUF 0x200
  280. #define _S_TIED_PUT_GET 0x400 // Set if put and get pointer logicly tied.
  281. #define _S_CURRENTLY_PUTTING 0x800
  282. #define _S_IS_APPENDING 0x1000
  283. #define _S_IS_BACKUPBUF 0x4000
  284. #define _S_IS_FILEBUF 0x8000
  285. #ifdef atarist
  286. #define _S_IS_BINARY 0x2000    // phew!! 
  287. #endif
  288.  
  289. // A streammarker remembers a position in a buffer.
  290. // You are guaranteed to be able to seek back to it if it is saving().
  291. class streammarker {
  292.     friend class streambuf;
  293. #ifdef _G_FRIEND_BUG
  294.     friend int __UNDERFLOW(streambuf*);
  295. #else
  296.     friend int __underflow(streambuf*);
  297. #endif
  298.     struct streammarker *_next;  // Only if saving()
  299.     streambuf *_sbuf; // Only valid if saving().
  300.     streampos _spos; // -2: means that _pos is valid.
  301.     void set_streampos(streampos sp) { _spos = sp; }
  302.     void set_offset(long offset) { _pos = offset; _spos = (streampos)(-2); }
  303.     // If _pos >= 0, it points to _buf->Gbase()+_pos.
  304.     // if _pos < 0, it points to _buf->eBptr()+_pos.
  305.     long _pos;
  306.   public:
  307.     streammarker(streambuf *sb);
  308.     ~streammarker();
  309.     int saving() { return  _spos == -2; }
  310.     int delta(streammarker&);
  311.     int delta();
  312. };
  313.  
  314. struct __streambuf {
  315.     // NOTE: If this is changed, also change __FILE in stdio/stdio.h!
  316.     unsigned long _flags; /* High-order word is _IO_MAGIC; rest is flags. */
  317.     char* _gptr;    /* Current get pointer */
  318.     char* _egptr;    /* End of get area. */
  319.     char* _eback;    /* Start of putback+get area. */
  320.     char* _pbase;    /* Start of put area. */
  321.     char* _pptr;    /* Current put pointer. */
  322.     char* _epptr;    /* End of put area. */
  323.     char* _base;    /* Start of reserve area. */
  324.     char* _ebuf;    /* End of reserve area. */
  325.     struct streambuf *_chain;
  326.  
  327.     // The following fields are used to support backing up and undo.
  328.     friend class streammarker;
  329.     char *_other_gbase; // Pointer to start of non-current get area.
  330.     char *_aux_limit;  // Pointer to first valid character of backup area,
  331.     char *_other_egptr; // Pointer to end of non-current get area.
  332.     streammarker *_markers;
  333.  
  334. #define __HAVE_COLUMN /* temporary */
  335.     // 1+column number of pbase(); 0 is unknown.
  336.     unsigned short _cur_column;
  337.     char _unused;
  338.     char _shortbuf[1];
  339. };
  340.  
  341. extern unsigned __adjust_column(unsigned start, const char *line, int count);
  342.  
  343. struct streambuf : public __streambuf {
  344.     friend class ios;
  345.     friend class istream;
  346.     friend class ostream;
  347.     friend class streammarker;
  348. #ifdef _G_FRIEND_BUG
  349.     friend int __UNDERFLOW(streambuf*);
  350. #else
  351.     friend int __underflow(streambuf*);
  352. #endif
  353.   protected:
  354.     static streambuf* _list_all; /* List of open streambufs. */
  355.     streambuf*& xchain() { return _chain; }
  356.     void _un_link();
  357.     void _link_in();
  358.     char* gptr() const { return _gptr; }
  359.     char* pptr() const { return _pptr; }
  360.     char* egptr() const { return _egptr; }
  361.     char* epptr() const { return _epptr; }
  362.     char* pbase() const { return _pbase; }
  363.     char* eback() const { return _eback; }
  364.     char* base() const { return _base; }
  365.     char* ebuf() const { return _ebuf; }
  366.     long blen() const { return _ebuf - _base; }
  367.     void xput_char(char c) { *_pptr++ = c; }
  368. #ifdef atarist
  369.     int  is_binary() { return ((_flags & _S_IS_BINARY) ? 1 : 0); }
  370.     void set_binary() { _flags |= _S_IS_BINARY; }
  371. #endif
  372.     unsigned long xflags() { return _flags; }
  373.     unsigned long xflags(unsigned long f) { unsigned long int fl = _flags; _flags = f; return fl; }
  374.     void xsetflags(unsigned long f) { _flags |= f; }
  375.     void xsetflags(unsigned long f, unsigned long mask) { _flags = (_flags & ~mask) | (f & mask); }
  376.     void gbump(_G_size_t n) { _gptr += n; }
  377.     void pbump(_G_size_t n) { _pptr += n; }
  378.     void setb(char* b, char* eb, int a=0);
  379.     void setp(char* p, char* ep) { _pbase=_pptr=p; _epptr=ep; }
  380.     void setg(char* eb, char* g, char *eg) { _eback=eb; _gptr=g; _egptr=eg; }
  381.     char *shortbuf() { return _shortbuf; }
  382.  
  383.     int in_backup() { return _flags & _S_IN_BACKUP; }
  384.     // The start of the main get area:  FIXME:  wrong for write-mode filebuf?
  385.     char *Gbase() { return in_backup() ? _other_gbase : _eback; }
  386.     // The end of the main get area:
  387.     char *eGptr() { return in_backup() ? _other_egptr : _egptr; }
  388.     // The start of the backup area:
  389.     char *Bbase() { return in_backup() ? _eback : _other_gbase; }
  390.     char *Bptr() { return _aux_limit; }
  391.     // The end of the backup area:
  392.     char *eBptr() { return in_backup() ? _egptr : _other_egptr; }
  393.     char *Nbase() { return _other_gbase; }
  394.     char *eNptr() { return _other_egptr; }
  395.     int have_backup() { return _other_gbase != NULL; }
  396.     int have_markers() { return _markers != NULL; }
  397.     long _least_marker();
  398.     void switch_to_main_get_area();
  399.     void switch_to_backup_area();
  400.     void free_backup_area();
  401.     void unsave_markers(); // Make all streammarkers !saving().
  402.     int put_mode() { return _flags & _S_CURRENTLY_PUTTING; }
  403.     int switch_to_get_mode();
  404.     
  405.     streambuf(unsigned long flags=0);
  406.   public:
  407.     static int flush_all();
  408.     static void flush_all_linebuffered(); // Flush all line buffered files.
  409.     virtual int underflow() = 0; // Leave public for now
  410.     virtual int overflow(int c = EOF) = 0; // Leave public for now
  411.     virtual int doallocate();
  412.     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
  413.     virtual streampos seekpos(streampos pos, int mode = ios::in|ios::out);
  414.     int seekmark(streammarker& mark, long delta = 0);
  415.     int sputbackc(char c);
  416.     int sungetc();
  417.     virtual ~streambuf();
  418.     int unbuffered() { return _flags & _S_UNBUFFERED ? 1 : 0; }
  419.     int linebuffered() { return _flags & _S_LINE_BUF ? 1 : 0; }
  420.     void unbuffered(int i)
  421.     { if (i) _flags |= _S_UNBUFFERED; else _flags &= ~_S_UNBUFFERED; }
  422.     void linebuffered(int i)
  423.     { if (i) _flags |= _S_LINE_BUF; else _flags &= ~_S_LINE_BUF; }
  424.     int allocate() { // For AT&T compatibility
  425.     if (base() || unbuffered()) return 0;
  426.     else return doallocate(); }
  427.     // Allocate a buffer if needed; use _shortbuf if appropriate.
  428.     void allocbuf() { if (base() == NULL) doallocbuf(); }
  429.     void doallocbuf();
  430.     virtual int sync();
  431.     virtual int pbackfail(int c);
  432.     virtual streambuf* setbuf(char* p, _G_size_t len);
  433.     long in_avail() { return _egptr - _gptr; }
  434.     long out_waiting() { return _pptr - _pbase; }
  435.     virtual _G_size_t xsputn(const char* s, _G_size_t n);
  436.     _G_size_t sputn(const char* s, _G_size_t n) { return xsputn(s, n); }
  437.     int padn(char pad, _G_size_t n); // Emit 'n' copies of 'pad'.
  438.     virtual _G_size_t xsgetn(char* s, _G_size_t n);
  439.     _G_size_t sgetn(char* s, _G_size_t n) { return xsgetn(s, n); }
  440.     _G_size_t ignore(_G_size_t);
  441.     virtual int get_column();
  442.     virtual int set_column(int);
  443.     long sgetline(char* buf, _G_size_t n, char delim, int putback_delim);
  444.     int sbumpc() {
  445.     if (_gptr >= _egptr && __underflow(this) == EOF) return EOF;
  446. #if 1 /* ndef atarist */
  447.     else return *(unsigned char*)_gptr++;
  448. #else
  449.         {
  450.         int ch = *(unsigned char*)_gptr++;
  451.         if((!is_binary()) && (ch == '\r'))
  452.         return sbumpc();
  453.         return ch;
  454.     }
  455. #endif
  456.  }
  457.     int sgetc() {
  458.     if (_gptr >= _egptr && __underflow(this) == EOF) return EOF;
  459. #if 1 /* ndef atarist */
  460.         return *(unsigned char*)_gptr;
  461. #else
  462.         {
  463.         int ch = *(unsigned char *)_gptr;
  464.         if((!is_binary()) && (ch == '\r'))
  465.         return snextc();
  466.         return ch;
  467.     }
  468. #endif    
  469.     }
  470.     int snextc() {
  471.     if (_gptr >= _egptr && __underflow(this) == EOF) return EOF;
  472.     else return _gptr++, sgetc(); }
  473. #if 0 /* def atarist -- not needed anymore because of stdibuf that uses
  474.      stdio to do writes with fwrite where text/bin mode are taken care of
  475.        */
  476.     int _atari_putc(int c) {
  477.     if ((!is_binary()) && ((c == '\n') || (c == '\r')))
  478.     {
  479.         if(c == '\r')
  480.         return (int)c;
  481.         if (_pptr >= _epptr)
  482.         {
  483.         if(__overflow(this, (unsigned char)'\r') == EOF) return EOF;
  484.         }
  485.         else
  486.         *_pptr++ = '\r';
  487.     }
  488.     if (_pptr >= _epptr) return __overflow(this, (unsigned char)c);
  489.     return *_pptr++ = c, (unsigned char)c;
  490.     }
  491. #endif
  492.     int sputc(int c) {
  493. #if 1 /* ndef atarist */
  494.     if (_pptr >= _epptr) return __overflow(this, (unsigned char)c);
  495.     return *_pptr++ = c, (unsigned char)c;
  496. #else
  497.     return _atari_putc(c);
  498. #endif    
  499.     }
  500.  
  501.     void stossc() { if (_gptr < _egptr) _gptr++; }
  502.     int vscan(char const *fmt0, _G_va_list ap, ios* stream = NULL);
  503.     int scan(char const *fmt0 ...);
  504.     int vform(char const *fmt0, _G_va_list ap);
  505.     int form(char const *fmt0 ...);
  506. #if 0 /* Work in progress */
  507.     int collumn();  // Current collumn number (of put pointer). -1 is unknown.
  508.     void collumn(int c);  // Set collumn number of put pointer to c.
  509. #endif
  510. };
  511.  
  512. // A backupbuf is a streambuf with full backup and savepoints on reading.
  513. // All standard streambufs in the GNU iostream library are backupbufs.
  514.  
  515. // A backupbuf may have two get area:
  516. // - The main get area, and (sometimes) the putback area.
  517. // Whichever one of these contains the gptr is the current get area;
  518. // the other one is the non-current get area.
  519.  
  520. class backupbuf : public streambuf {
  521.     friend class streammarker;
  522.   protected:
  523.     backupbuf(int flags=0) : streambuf(flags|_S_IS_BACKUPBUF) { }
  524.   public:
  525.     virtual int pbackfail(int c);
  526.     virtual int underflow();
  527.     virtual int overflow(int c = EOF);
  528. };
  529.  
  530. struct __file_fields {
  531.     short _fileno;
  532.     _G_size_t _blksize;
  533.     _G_off_t _offset;
  534. //    char* _save_gptr;  char* _save_egptr;
  535. };
  536.  
  537. class filebuf : public backupbuf {
  538.   protected:
  539.     struct __file_fields _fb;
  540.     void init();
  541.   public:
  542.     static const int openprot; // Non-ANSI AT&T-ism:  Default open protection.
  543.     filebuf();
  544.     filebuf(int fd);
  545.     filebuf(int fd, char* p, _G_size_t len);
  546.     ~filebuf();
  547.     filebuf* attach(int fd);
  548.     filebuf* open(const char *filename, const char *mode);
  549.     filebuf* open(const char *filename, ios::openmode mode, int prot = 0664);
  550.     virtual int underflow();
  551.     virtual int overflow(int c = EOF);
  552.     int is_open() const { return _fb._fileno >= 0; }
  553.     int fd() const { return is_open() ? _fb._fileno : EOF; }
  554.     filebuf* close();
  555.     virtual int doallocate();
  556.     virtual streampos seekoff(streamoff, _seek_dir, int mode=ios::in|ios::out);
  557.     virtual streambuf* setbuf(char* p, _G_size_t len);
  558.     _G_size_t xsputn(const char* s, _G_size_t n);
  559.     _G_size_t xsgetn(char* s, _G_size_t n);
  560.     virtual int sync();
  561.   protected: // See documentation in filebuf.C.
  562. //    virtual int pbackfail(int c);
  563.     int is_reading() { return eback() != egptr(); }
  564.     char* cur_ptr() { return is_reading() ?  gptr() : pptr(); }
  565.     /* System's idea of pointer */
  566.     char* file_ptr() { return eGptr(); }
  567.     int do_write(const char *data, _G_size_t to_do);
  568.     int do_flush() { return do_write(_pbase, _pptr-_pbase); }
  569.     // Low-level operations (Usually invoke system calls.)
  570.     virtual _G_ssize_t sys_read(char* buf, _G_size_t size);
  571.     virtual _G_fpos_t sys_seek(_G_fpos_t, _seek_dir);
  572.     virtual _G_ssize_t sys_write(const void*, _G_size_t n);
  573.     virtual int sys_stat(void*); // Actually, a (struct stat*)
  574.     virtual int sys_close();
  575. };
  576.  
  577. inline ios::ios(streambuf* sb /* = 0 */, ostream* tie_to /* = 0 */) {
  578.         _state = sb ? ios::goodbit : ios::badbit; _exceptions=0;
  579.         _strbuf=sb; _tie = tie_to; _width=0; _fill=' ';
  580.         _flags=ios::skipws|ios::dec; _precision=6; }
  581. inline ios::~ios() {
  582.     if (!(_flags & (unsigned int)ios::dont_close)) delete _strbuf; }
  583.  
  584. #endif /* _STREAMBUF_H */
  585.